#define _CRT_SECURE_NO_WARNINGS 1
#include "RBTree.hpp"
#include <map>
namespace lnb
{
	template<class K, class V>
	class map
	{
		struct KeyOfValue
		{
			const K& operator()(const pair<const K,V>& kv)
			{
				return kv.first;
			}
		};
	
	public:
		typedef lnb::RBTree<K,pair<const K,V>,KeyOfValue> RBTree;

		typedef typename RBTree::iterator iterator;
		typedef typename RBTree::const_iterator const_iterator;
		pair<iterator, bool>Insert(const pair<K, V>& kv)
		{
			return _tree.Insert(kv);
		}
		auto begin()
		{
			return _tree.begin();
		}
		auto end()
		{
			return _tree.end();
		}

		V& operator[](const K& key)
		{
			return (((_tree.Insert(make_pair(key, V()))).first)->second);
		}


	private:

		RBTree _tree;

	};
	void MapTest()
	{
		map<int, int> m;
		/*	m.Insert(make_pair(30, 2));
			m.Insert(make_pair(90, 2));
			m.Insert(make_pair(60, 2));
			m.Insert(make_pair(4, 2));
			m.Insert(make_pair(3, 2));
			m.Insert(make_pair(7, 2));*/
		cout<<typeid(m.Insert(make_pair(1, 2))).name()<<endl;
		m.Insert(make_pair(3, 2));
		m.Insert(make_pair(4, 2));
		map<int, int>::iterator it = m.begin();
		while (it!=m.end())
		{
			cout << it->first << " ";			
			++it;
			
		}
		cout << endl;
		cout<<m[1]<<endl;
	}

}